<?php
//dezend by http://www.yunlu99.com/ QQ:270656184
defined('BASEPATH') || exit('No direct script access allowed');
class Support extends MY_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->verify_user();
	}

	public function index()
	{
		$this->view('support');
	}

	public function data()
	{
		$page = ($this->input->post('page') ? intval($this->input->post('page')) : 1);
		$rows = ($this->input->post('rows') ? intval($this->input->post('rows')) : 10);
		$id = intval($this->input->post('id'));
		$status = $this->input->post('status');
		$username = $this->input->post('username');
		$start = $this->input->post('start');
		$end = $this->input->post('end');
		$where[1] = 1;

		if ($username) {
			$user = $this->db->where('username', $username)->get('user')->row_array();

			if ($user) {
				$where['user_id'] = $user['id'];
			}
		}

		if ($start) {
			$where['add_time>='] = strtotime($start);
		}

		if ($end) {
			$where['add_time<='] = strtotime($end);
		}

		if ($id) {
			$where['no'] = $id;
		}

		if ((0 <= $status) && ($status != NULL)) {
			$where['status'] = $status;
		}

		$result['total'] = $this->db->where($where)->count_all_results('support');
		$start = ($page - 1) * $rows;
		$result['rows'] = $this->db->where($where)->limit($rows, $start)->get('support')->result_array();

		foreach ($result['rows'] as $k => $v) {
			$result['rows'][$k]['add_time'] = date('Y-m-d H:i', $v['add_time']);
			$result['rows'][$k]['coin_name'] = $this->d->field(array('field' => 'cn_name', 'where' => 'id=' . $v['coin_id'], 'table' => 'coin'));
			$result['rows'][$k]['username'] = $this->d->field(array('field' => 'username', 'where' => 'id=' . $v['user_id'], 'table' => 'user'));
			$result['rows'][$k]['item_name'] = $this->d->field(array('field' => 'name', 'where' => 'id=' . $v['item_id'], 'table' => 'items'));
		}

		echo json_encode($result);
	}
}

?>
